import Vue from 'vue'
import Router from 'vue-router'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUi from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import i18n from "@/styles/js/i18nIndex";
import moment from 'moment'
import '@/styles/css/global.css';
import * as eCharts from "echarts";
Vue.use(ElementUi)
Vue.config.productionTip = false
Vue.prototype.moment = moment
const routerPush: any = Router.prototype.push
Router.prototype.push = function push(location) {
 return routerPush.call(this, location).catch((error: any)=> error)
}
Vue.prototype.$echarts = eCharts

router.beforeEach((to,from,next) =>{
    let token = localStorage.getItem("token")
    if (to.matched.some(function (item) {
        return item.meta.login_required
    }) && !token) {
        console.log("router.beforeEach........")
        // TODO 将跳转的路由path作为参数，登录成功跳转到该路由
        // next({
        //     path: '/login',
        //     query: {
        //         redirect: to.fullPath,
        //     }
        // })
        next('/login')
    } else {
        next();
    }
})

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
